﻿//告诉Ember.js，当应用的URL与 '/' 匹配时，渲染 todos 模板。
Todos.Router.map(function () {
    this.resource('todos', { path: '/' }, function () {
        // 其他子路由
        this.route('active');
        this.route('completed');
    });
});

Todos.TodosRoute = Ember.Route.extend({
    model: function () {
        return Todos.Todo.find();
    }
});

Todos.TodosIndexRoute = Ember.Route.extend({
    model: function () {
        return Todos.Todo.find();
    }
});

Todos.TodosActiveRoute = Ember.Route.extend({
    model: function () {
        return Todos.Todo.filter(function (todo) {
            if (!todo.get('isCompleted')) { return true; }
        });
    },
    renderTemplate: function (controller) {
        this.render('todos/index', { controller: controller });
    }
});

Todos.TodosCompletedRoute = Ember.Route.extend({
    model: function () {
        return Todos.Todo.filter(function (todo) {
            if (todo.get('isCompleted')) { return true; }
        });
    },
    renderTemplate: function (controller) {
        this.render('todos/index', { controller: controller });
    }
});